package com.gc.server.service.impl;

import com.gc.server.dao.GoodsDao;
import com.gc.server.entity.GoodsEntity;
import com.gc.server.entity.TodoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.gc.server.dao.GoodsRecordDao;
import com.gc.server.entity.GoodsRecordEntity;
import com.gc.server.service.GoodsRecordService;
import com.yf.service.impl.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * 业务员物料消费Service实现类
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Tue Mar 10 11:17:45 CST 2020
 */
@Service
public class GoodsRecordServiceImpl extends BaseServiceImpl<GoodsRecordEntity> implements GoodsRecordService {

    private GoodsRecordDao goodsRecordDao;

    private GoodsDao goodsDao;

    @Autowired
    public void setGoodsDao(GoodsDao goodsDao) {
        this.goodsDao = goodsDao;
    }

    @Autowired
    public void setDao(GoodsRecordDao goodsRecordDao) {
        this.goodsRecordDao = goodsRecordDao;
        super.setBaseDao(goodsRecordDao);
    }


    /**
     *
     *   @Override
     *     public List<UserVo> queryListVo(UserVo userVo) {
     *         return userDao.queryListVo(userVo);
     *     }
     *
     *     @Override
     *     public UserVo getVo(Long id) {
     *         return userDao.getVo(id);
     *     }

     @Override
     List<GoodsRecordVo> queryListVo(GoodsRecordVo goodsRecordVo){
            return goodsRecordDao.queryListVo(goodsRecordVo);
     }

     @Override
     GoodsRecordVo getVo(Long id){
                return goodsRecordDao.getVo(id);
    }

     **/


    /**内部方法**/



    /**外部方法实现**/


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void record(Long userId,Long todoId, Long[] goodsIds, Integer[] numbers) {
        goodsRecordDao.removeByToDoId(todoId);
        for (int i = 0; i < goodsIds.length; i++) {
            GoodsEntity goodsEntity = goodsDao.get(goodsIds[i]);
            GoodsRecordEntity goodsRecordEntity = new GoodsRecordEntity(userId,todoId,goodsEntity.getId(),goodsEntity.getName(),numbers[i]);
            goodsRecordDao.save(goodsRecordEntity);
        }
    }

    @Override
    public List<GoodsRecordEntity> findByToDoId(Long toId) {
        return goodsRecordDao.findByToDoId(toId);
    }
}
